import java.util.Scanner;

public class Main {
    static int[] arr = new int[1024];
    static int[] vis = new int[1024];
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        dfs(0,n);


    }
    public static void dfs(int cur,int n){
        if(cur==n){
            for(int i=0;i<n;i++){
                System.out.print(arr[i] + " ");
            }
            System.out.println();
        }

        for(int i=1;i<=n;i++){
            if(vis[i]==1){
                continue;
            }
            arr[cur]=i;
            vis[i]=1;
            dfs(cur+1,n);
            vis[i]=0;
        }

    }
}
